package com.shangxia.lucky.lucky.job;

import com.shangxia.lucky.lucky.entity.Model;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @ProjectName: monomer
 * @ClassName: MatchGroupWithOutRedJob
 * @Time: 2021/9/20
 * @Author: zhouy
 * @Description:
 * @Experience:
 */
@Slf4j
@Component
public class MatchGroupWithOutRedJob extends MatchGroupJob{


    @Override
    public void doPrivateJob(Map<String, Object> params, List<List<Integer>> realCodeLists) {
        List<List<Integer>> matchLists = (List<List<Integer>>) params.get("matchLists");
        List<Integer> columnList = (List<Integer>) params.get("columnList");
        Integer row = (Integer) params.get("row");
        Integer column = (Integer) params.get("column");
        for (int type = 0; type < matchLists.size(); type++) {
            Set<Integer> set = new HashSet<>(matchLists.get(type));
            set.addAll(columnList.subList(configText.getBananaCodeLength() - configText.getBananaSonCodeLength(), columnList.size()));
            //匹配个数
            int matchCount = configText.getBananaSonCodeLength() + matchLists.get(type).size() - set.size();
            Model model = new Model();
            model.setRow(row);
            model.setColumn(column);
            model.setType(type);
            model.setMatchCount(matchCount);
            model.setPrized(matchCount == Math.min(matchLists.get(type).size(), configText.getBananaSonCodeLength()));
            if (row.equals(column)) {
                model.setAge(1);
                model.setMatchCountAll(matchCount);
            } else {
                Model lastModel = ROW_LAST_MODELS.get(column + "&" + type);
                if (model.getPrized()) {
                    model.setAge(1);
                } else {
                    model.setAge(lastModel.getAge() + 1);
                }
                model.setMatchCountAll(lastModel.getMatchCountAll() + matchCount);
            }
            if (0 != model.getMatchCountAll()) {
                Double aveMatchCount = 1.0 * model.getMatchCountAll() / (1 + row - column);
                model.setAveMatchCount(String.format("%.2f", aveMatchCount));
            } else {
                model.setAveMatchCount("0");
            }
            ROW_MODELS.put(column + "&" + type, model);
        }
    }

}
